import helpers
from unittest import TestCase
from pagamigo.RequestSession import RequestSession
from pagamigo.Authentication import flow as authentication_flow
from pagamigo.Redirect import flow as redirect_flow


def logger(data):
    print(data)


class TestRedirect(TestCase):
    def test_redirect_flow(self):
        config = helpers.get_paypal_sandbox_config_from_json()
        session = RequestSession("https://www.sandbox.paypal.com", logger)

        # Log the user in and then send funds
        response = authentication_flow(session, config["paypal_sandbox_email"],
                                       config["paypal_sandbox_password"],
                                       config["paypal_sandbox_country"])

        # an exception will be thrown if this operation doesn't succeed
        response = redirect_flow(session, config["test_url_for_redirect"], "https://www.sandbox.paypal.com",
                                   config["paypal_sandbox_country"], "en")
        assert response is not None
